home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////
- /*
- File: mfcdde.h
- Purpose: MFC DDE classes
- Author: Julian Smart
-
- Note:
- Minor modifications have been made to the original class by Julian
- Smart. Along with some formating and slight documentation changes a
- private member variable m_nTimeOut is now used to specifiy the timeout
- for DDE transactions. A new member funciton SetTimeout can be used to
- set a new timeout value. This new function also returns the currrent
- timeout value.
- */
-
-
- #ifndef MFCDDEH
- #define MFCDDEH
-
- /////////////////////////////////////////////////////////////////////
- // Includes
- //
- #include <ddeml.h>
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Mini-Dde implementation
-
- Most transactions involve a topic name and an item name.
-
- A client can:
-
- - ask the server to execute commands (data) associated with a topic
- - request data from server by topic and item
- - poke data into the server
- - ask the server to start an advice loop on topic/item
- - ask the server to stop an advice loop
-
- A server can:
-
- - respond to execute, request, poke and advice start/stop
- - send advise data to client
-
- Note that this limits the server in the ways it can send data to the
- client, i.e. it can't send unsolicited information.
- */
-
- /////////////////////////////////////////////////////////////////////
- // Function Prototypes
- //
- void DdeInitialize();
- void DdeCleanUp();
-
- /////////////////////////////////////////////////////////////////////
- // Defines
- //
- #define DEFAULT_TIMEOUT 5000
-
- /////////////////////////////////////////////////////////////////////
- // Foreward Class Declarations
- //
- class CDdeServer;
- class CDdeClient;
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Class: CDdeConnection : public CObject
-
- Description:
-
- Notes:
-
- */
- class CDdeConnection : public CObject
- {
- public:
- long m_nConversationId;
- char *m_pIpcBuffer;
- int m_nIpcBufferSize;
- CString m_sTopicName;
- CDdeServer *m_pServer;
- CDdeClient *m_pClient;
-
- HCONV m_hConv;
- char *m_pSendingData;
- int m_nSendingDataSize;
- int m_nSendingDataType;
-
- CDdeConnection(char *pIpcBuffer, int nIpcBufferSize);
- CDdeConnection(void);
- ~CDdeConnection(void);
-
- /////////////////////////////////////////////////////////////////////
- // Calls that CLIENT can make
- //
- DWORD SetTimeOut(DWORD nTimeOut);
- virtual BOOL Execute(char *pData, int nDataSize = -1, int nFormat = CF_TEXT);
- virtual BOOL Execute(const CString& sData)
- {
- return Execute((char *)(const char *)sData, -1, CF_TEXT);
- }
- virtual char *Request(const CString& sItem, int *pnDataSize = NULL, int nFormat = CF_TEXT);
- virtual BOOL Poke(const CString& sItem, char *pData, int nDataSize = -1, int nFormat = CF_TEXT);
- virtual BOOL StartAdvise(const CString& sItem);
- virtual BOOL StopAdvise(const CString& sItem);
-
- /////////////////////////////////////////////////////////////////////
- // Calls that SERVER can make
- //
- virtual BOOL Advise(const CString& sItem, char *pData, int nDataSize = -1, int nFormat = CF_TEXT);
-
- /////////////////////////////////////////////////////////////////////
- // Calls that BOTH can make
- //
- virtual BOOL Disconnect(void);
- virtual void Notify(BOOL bNotify); // Internal use only
-
- /////////////////////////////////////////////////////////////////////
- // Callbacks to SERVER - override at will
- //
- virtual BOOL OnExecute(const CString& sTopic, char *pData, int nDataSize, int nFormat)
- {
- return FALSE;
- };
- virtual char *OnRequest(const CString& sTopic, const CString& sItem, int *nDataSize, int nFormat)
- {
- return NULL;
- };
- virtual BOOL OnPoke(const CString& sTopic, const CString& sItem, char *pData, int nDataSize, int nFormat)
- {
- return FALSE;
- };
- virtual BOOL OnStartAdvise(const CString& sTopic, const CString& sItem)
- {
- return FALSE;
- };
- virtual BOOL OnStopAdvise(const CString& sTopic, const CString& sItem)
- {
- return FALSE;
- };
-
- /////////////////////////////////////////////////////////////////////
- // Callbacks to CLIENT - override at will
- //
- virtual BOOL OnAdvise(const CString& sTopic, const CString& sItem, char *pData, int nDataSize, int nFormat)
- {
- return FALSE;
- };
-
- /////////////////////////////////////////////////////////////////////
- // Callbacks to BOTH
- //
-
- /////////////////////////////////////////////////////////////////////
- // Default behaviour is to delete connection and return TRUE
- //
- virtual BOOL OnDisconnect(void);
-
- private:
- DWORD m_nTimeOut;
- };
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Class: CDdeObject : public CObject
-
- Description:
-
- Notes:
-
- */
- class CDdeObject : public CObject
- {
- public:
- int lastError;
- CString m_sServiceName; // Server only
- CObList m_Connections;
-
- CDdeObject(void);
- ~CDdeObject(void);
-
- // Find/delete CDdeConnection corresponding to the HCONV
- CDdeConnection *FindConnection(HCONV hConv);
- BOOL DeleteConnection(HCONV hConv);
- };
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Class: CDdeServer : public CDdeObject
-
- Description:
-
- Notes:
-
- */
- class CDdeServer : public CDdeObject
- {
- public:
-
- CDdeServer(void);
- ~CDdeServer(void);
- BOOL Create(const CString& sServerName); // Returns FALSE if can't create server (e.g. port
- // number is already in use)
- virtual CDdeConnection *OnAcceptConnection(const CString& sTopic);
- };
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: CDdeClient : public CDdeObject
-
- Description:
-
- Notes:
-
- */
- class CDdeClient : public CDdeObject
- {
- public:
- CDdeClient(void);
- ~CDdeClient(void);
- BOOL ValidHost(const CString& sHostName);
- virtual CDdeConnection *MakeConnection(const CString& sHostName, const CString& sServerName, const CString& sTopic);
- // Call this to make a connection.
- // Returns NULL if cannot.
- virtual CDdeConnection *OnMakeConnection(void); // Tailor this to return own connection.
- };
-
-
- #endif
-